package com.ruoyi.system.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import java.util.Arrays;


/**
 * ClassName: CorsConfig
 * Package: mms.common.config
 * Description:
 *
 * @Author ban
 * @Create 2025/3/4 16:35
 * @Version 1.0
 */
//@Configuration
public class CorsConfig {

//    @Bean
    public CorsFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();
        // 严格限制允许的 Origin 值
        config.setAllowedOrigins(Arrays.asList("http://10.31.88.23:9033", "http://10.31.88.23:9034","http://127.0.0.1:9033"));
        config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
        config.setAllowedHeaders(Arrays.asList("*"));
        config.setAllowCredentials(true);
        config.setMaxAge(3600L);

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", config);
        return new CorsFilter(source);
    }
}